//
//  FKFindLoginPwdVC.m
//  inspectVehicle
//
//  Created by Macbook Pro on 2018/12/12.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKFindLoginPwdVC.h"

@interface FKFindLoginPwdVC ()

@property (weak, nonatomic) IBOutlet UITextField *mobileField;
@property (weak, nonatomic) IBOutlet UITextField *codeField;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UITextField *confirmPwdField;
@property (weak, nonatomic) IBOutlet UIButton *getCodeBtn;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;

@property (nonatomic, copy) NSString *mobile;

@end

@implementation FKFindLoginPwdVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSDictionary *userInfo = [FKCacheTool userInfo][@"info"];
    self.mobile = userInfo[@"mobile"];
    if (self.mobile.length == 11) {
        NSString *subStr = [self.mobile substringWithRange:NSMakeRange(3, 4)];
        self.mobileField.text = [self.mobile stringByReplacingOccurrencesOfString:subStr withString:@"****"];
    }
}

- (IBAction)getCodeBtnClicked:(UIButton *)sender {
    sender.enabled = false;
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"mobile"] = self.mobile;
    param[@"type"] = @"2";
    [FKHttpTool postWithSuffix:@"m=App&c=Member&a=get_code" param:param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            [SVProgressHUD showSuccessWithStatus:@"验证码发送成功"];
            [sender fk_startWithTime:59 title:@"重新发送" countDownTitle:@"秒" normalColor:nil countdownColor:nil];
        }
    } failure:nil];
}

- (IBAction)confirmBtnClicked:(UIButton *)sender {
    [self.view endEditing:true];
    
    if (self.codeField.text.length < 1) {
        [SVProgressHUD showInfoWithStatus:self.codeField.placeholder];
        return;
    }
    if (self.pwdField.text.length < 1) {
        [SVProgressHUD showInfoWithStatus:self.pwdField.placeholder];
        return;
    }
    if (self.confirmPwdField.text.length < 1) {
        [SVProgressHUD showInfoWithStatus:self.confirmPwdField.placeholder];
        return;
    }
    if (![self.pwdField.text isEqualToString:self.confirmPwdField.text]) {
        [SVProgressHUD showInfoWithStatus:@"新密码与确认密码不一致!"];
        return;
    }
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"mobile"] = self.mobile;
    param[@"code"] = self.codeField.text;
    param[@"password"] = self.pwdField.text;
    param[@"confirm_password"] = self.confirmPwdField.text;
    [SVProgressHUD show];
    [FKHttpTool postWithSuffix:@"m=App&c=Member&a=findpwd" param:param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            [SVProgressHUD dismiss];
            [SVProgressHUD showSuccessWithStatus:@"登录密码修改成功!"];
//            kPopVC;
            [self.navigationController popToRootViewControllerAnimated:true];
        }
    } failure:nil];
}



@end
